package com.hxzy.springbootrabbitmqproducer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 发布订阅模型类说明
 * 一个交换机exchange 可以绑定多个队列
 *
 * @author admin
 * @date 2021-07-22
 * finished
 */
@Configuration
public class FanoutExchangeConfig {

    /**
     * 创建一个队列模型邮箱
     * @return
     */
    @Bean
    public Queue emailQueue(){
        return new Queue("hxzy_email");
    }

    /**
     * 创建一个队列模型手机
     * @return
     */
    @Bean
    public Queue mobileQueue(){
        return new Queue("hxzy_mobile");
    }

    /**
     * 消息队列模型交换机
     * @return
     */
    @Bean
    public FanoutExchange  fanoutExchange(){

        return new FanoutExchange("shop.fanout");
    }

    /**
     *  hxzy_email队列绑定给交换机
     * @param mobileQueue
     * @param fanoutExchange
     * @return
     * springframework.amqp.core-->BindingBuilder
     */
    @Bean
    public Binding fanoutExchangeBindEmailQueue(Queue mobileQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(mobileQueue).to(fanoutExchange);
    }

    /**
     *  hxzy_mobile队列绑定给交换机
     * @param emailQueue
     * @param fanoutExchange
     * @return
     */
    @Bean
    public Binding fanoutExchangeBindMobileQueue(Queue emailQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(emailQueue).to(fanoutExchange);
    }

}
